<?php

namespace app\admin\model\activityone;

use think\Model;
use think\Db;

class Activitydetail extends Model
{

    

    

    // 表名
    protected $name = 'events_guess';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = false;

    // 定义时间戳字段名
    protected $createTime = false;
    protected $updateTime = false;
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'status_text',
        'coupon_text',
        'winner_team_text'
    ];
    

    
    public function getStatusList()
    {
        return ['10' => __('Status 10')];
    }


    public function getWinnerTeamTextAttr($value, $data)
    {
        $lists = Db::name('event_guess_teams')
            ->whereIn('id', $data['winner_team_id'])
            ->column('name');
        return implode(',', $lists);
    }

    public function getCouponTextAttr($value, $data)
    {
        $lists = Db::name('shopro_coupon')
            ->whereIn('id', $data['giftCoupon'])
            ->column('name');
        return implode(',', $lists);
    }


    public function getStatusTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
        $list = $this->getStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }

    public function coupon(){
        $couponlist = Db::name('shopro_coupon')->order('id desc')->select();
        return $couponlist;
    }
   
    public function couponsta()

    {
        return $this->belongsTo('\app\admin\model\shopro\Coupon', 'giftCoupon', 'id', [], 'LEFT')->setEagerlyType(0);

    }

}
